package com.lykj.lib_base.internal.utils

import android.content.Context
import android.content.pm.PackageManager
import java.io.File

/**
 * ================================================
 * 文件工具类
 * ================================================
 *
 * @author gosha
 * @date 2022/9/6-17:09
 */
object LYFileUtils {

    /**
     * 获取文件扩展名
     */
    fun getFileExt(str: String): String {
        var p = str.lastIndexOf(".")
        return str.substring(p)
    }

    /**
     * 获取文件名(带扩展名)
     */
    fun getFileNameFromUrl(url: String): String {
        var p = url.lastIndexOf("/")
        return url.substring(p + 1)
    }

    //获取apk应用包名
    fun getPkgName(context: Context, file: File): String? {
        var pkgName = ""
        val pm = context.applicationContext.packageManager
        val packageInfo = pm.getPackageArchiveInfo(file.path, PackageManager.GET_ACTIVITIES)
        if (packageInfo != null) {
            pkgName = packageInfo.applicationInfo.packageName
        }
        return pkgName
    }
}